Repository navigation
Prevent Listbox selection while disabled - #3912
Open
Xapollon430 wants to merge 2 commits into
Open
Xapollon430 wants to merge 2 commits into
Xapollon430 wants to merge 2 commits into
Conversation
Xapollon430
marked this pull request as ready for review
November 1, 2026 23:00
|
@Xapollon430 is attempting to deploy a commit to the Tailwind Labs Team on Vercel. A member of the Team first needs to authorize it. |
Xapollon430
marked this pull request as draft
November 1, 2026 23:19
Xapollon430
marked this pull request as ready for review
November 2, 2026 01:30
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I was playing around with the
Listboxcomponent and noticed a bug where:disabledtotruewhile the menu is open.onChangestill fires.Here is a reproduction video of the issue:
Recorded against published
@headlessui/react2.2.10 before the fix. The disabled-state readout stays visible, and selection uses a normal pointer click.headless-audited-repro.mp4
A prop update can send
disabled=trueafter the menu is already open. In an application, that could happen when an asynchronous request completes or a timer fires while someone is choosing an option. The case here is the parent control becoming disabled; the options haven't been individually marked disabled.My first thought was to close the popup, since that is what I observed with a native HTML
selectin Chromium. The HTML option-picking algorithm also stops without selecting an option when its select is disabled.Closing on disable is a reasonable choice too. I'm happy to adjust the PR to follow the library's preferred behavior. The behavior I'm trying to guarantee is simply that a control stops accepting user selections once it becomes disabled.
The options inherit the parent Listbox's disabled state, so pointer and keyboard selection stop while disabled. The PR applies the same behavior to the React and Vue implementations and leaves the current menu state alone.
I started investigating this interaction while using Hegel to vary component props and Bombadil to exercise UI actions in Anta. I then reproduced this library's behavior separately; the video above is from that reproduction.
Validation
npx jest --runInBand --selectProjects React --runTestsByPath packages/@headlessui-react/src/components/listbox/listbox.test.tsx